package hotciv.common;

import hotciv.framework.*;

public class HotCivLoggingDecorator implements Game {

	Game game;
	
	public HotCivLoggingDecorator(Game game) {
		this.game = game;
	}
	
	@Override
	public Tile getTileAt(Position p) {
		return game.getTileAt(p);
	}

	@Override
	public Unit getUnitAt(Position p) {
		return game.getUnitAt(p);
	}

	@Override
	public City getCityAt(Position p) {
		return game.getCityAt(p);
	}

	@Override
	public Player getPlayerInTurn() {
		return game.getPlayerInTurn();
	}

	@Override
	public Player getWinner() {
		return game.getWinner();
	}

	@Override
	public int getAge() {
		return game.getAge();
	}

	@Override
	public boolean moveUnit(Position from, Position to) {
		Unit u = getUnitAt(from);
		boolean unitMoved = game.moveUnit(from, to);
		if (unitMoved) {
			saveToLog(getPlayerInTurn() + " moves " + u.getTypeString() + " from " + from + " to  " + to + ".");
		}
		return unitMoved;
	}

	@Override
	public void endOfTurn() {
		saveToLog(getPlayerInTurn() + " ends turn.");
		game.endOfTurn();
	}

	@Override
	public void changeWorkForceFocusInCityAt(Position p, String balance) {
		saveToLog(getPlayerInTurn() + " changes work force focus in city at " + p + " to " + balance + ".");
		game.changeWorkForceFocusInCityAt(p, balance);
	}

	@Override
	public void changeProductionInCityAt(Position p, String unitType) {
		saveToLog(getPlayerInTurn() + " changes production in city at " + p + " to " + unitType + ".");
		game.changeProductionInCityAt(p, unitType);
	}

	@Override
	public void performUnitActionAt(Position p) {
		Unit u = getUnitAt(p);
		saveToLog(getPlayerInTurn() + " performs unit action with " + u.getTypeString() + " at " + p + ".");
		game.performUnitActionAt(p);
	}

	@Override
	public void setTileFocus(Position p) {
		game.setTileFocus(p);
	}

	@Override
	public void addObserver(GameObserver o) {
		game.addObserver(o);
		
	}
	
	private void saveToLog(String str) {
		System.out.println(str);
	}

}
